/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Inc. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 * 
 * Official Website 
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
var appslide =
{   
    _obj       :null,
    _ttime     :100, 
    _data      :Array(),
    _l_img     :base + '/images/loadinfo.net.gif', 
    _l_obj     :'.app-press-menu',
    show_img   :function(item)
                {
                    item.setStyle('display','block');
                    item.setOpacity(.2);	
                    item.fade('in');
                },
    chimg      :function(_obj)
                {
                     $$('.press-img-pan').getChildren('img')[0].each(function(item, index){
                        if(item.src.search(_obj.get('rel'))>0)appslide.show_img(item);
                        else item.setStyle('display','none');
                    });

                },
    clrsec     :function()
                {
                    $$('.app-press-menu').getChildren('a')[0].each(function(item, index){
                        item.removeClass('selected');  
                    })
                },
    loading    :function(ptr)
                {
                    if(ptr)$$(appslide._l_obj).setStyle('background','url(' + appslide._l_img + ') left top no-repeat');
                    else $$(appslide._l_obj).setStyle('background','none');
                },
    view       :function()
                {
                    appslide._obj = this;
                    if(!$chk(appslide._data[appslide._obj.get('longdesc')]))
                    {
                        appslide.loading(true);
                        new Request({url:base, 
                            onSuccess: function(responseTxt) 
                            {	
                                appslide._data[appslide._obj.get('longdesc')] =responseTxt ;
                                appslide.chimg(appslide._obj);
                                appslide.clrsec();
                                appslide._obj.addClass('selected');
                                $$('.app-press-text').set('html',appslide._data[appslide._obj.get('longdesc')]);
                                Cufon.replace('h1');
                                appslide.loading(false);
                               
                            },
                            onFailure: function() {alert("Check your connection.");}
                        }).send({url:base + "/appslide/index/" + this.get('longdesc')});
                    }
                    else
                    {
                        appslide.chimg(appslide._obj);
                        appslide.clrsec();
                        appslide._obj.addClass('selected');
                        $$('.app-press-text').set('html',appslide._data[appslide._obj.get('longdesc')]);
                        Cufon.replace('h1');
                    }
					
                },
    loadimage  :function(image)
                {
                   var myFirstElement = new Element('img', {src: base + '/uploads/filemanager/' + image,style:'width:390px;display:none'});
  			       $$('.press-img-pan').grab(myFirstElement, 'bottom');
                },
    init       :function()
                {
					if($chk($$('.app-press-menu').getChildren('a')[0]))
					{
						$$('.app-press-menu').getChildren('a')[0].each(function(item, index){
							appslide.loadimage(item.get('rel'));
							item.addEvent('click', appslide.view);
						});	
					}
                    
                }
}

window.addEvent('load', appslide.init);